﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Private_NoPromotion.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content2" ContentPlaceHolderID="TitleHolder" runat="server">Danh sách hình ảnh
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadHolder" runat="server">
    <script type="text/javascript">
        var totalPage = <%=(int)Math.Ceiling(double.Parse(ViewData["NumAlbums"].ToString())/WebHoiChoMuaBan.Controllers.Global.Config.PAGE_NUMBER_VISIABLE) %>;
        var pageNumVisible = <%=WebHoiChoMuaBan.Controllers.Global.Config.PAGE_NUMBER_VISIABLE %>;
        var maxCurrentPage = 4;
        var indexAlbumVisible = 1;
        var indexPhotoAlbum = 1;
        
        $(document).ready(function () {
            $('#pageIndexAlbum' + indexAlbumVisible).css('color', 'red');
            $('#pageAvailable1').css('display', 'inline');
            $('#aPhotoOfAlbum1').css('color', 'red');
        });

        function Preview() {
            if ($('#aNext').css('visibility') == "hidden")
                $('#aNext').css('visibility', 'visible');
            for (var i = maxCurrentPage - 3; i <= maxCurrentPage; i++) {
                $('#pageIndexAlbum' + i).css('display', 'none');
            }
            maxCurrentPage = maxCurrentPage - 4;
            if (maxCurrentPage < pageNumVisible){
                maxCurrentPage = pageNumVisible;
                $('#aPreview').css('visibility', 'hidden');
            }
            for (var i = maxCurrentPage; i >= maxCurrentPage - 3; i--) {
                $('#pageIndexAlbum' + i).css('display', 'inline');
            }
        }

        function Next() {
            if ($('#aPreview').css('visibility') == "hidden")
                $('#aPreview').css('visibility', 'visible');
            for (var i = maxCurrentPage - 3; i <= maxCurrentPage; i++) {
                $('#pageIndexAlbum' + i).css('display', 'none');
            }
            maxCurrentPage = maxCurrentPage + 4;
            if (maxCurrentPage > totalPage){
                maxCurrentPage = totalPage;
                $('#aNext').css('visibility', 'hidden');
            }
            for (var i = maxCurrentPage; i >= maxCurrentPage - 3; i--) {
                $('#pageIndexAlbum' + i).css('display', 'inline');
            }
        }

        function ToIndexAlbum(albumPage){
            //Hidden
            var begin  = (indexAlbumVisible - 1)*<%=WebHoiChoMuaBan.Controllers.Global.Config.NUM_ALBUM_SHOW_IN_PAGE %> + 1;
            var end = begin + <%=WebHoiChoMuaBan.Controllers.Global.Config.NUM_ALBUM_SHOW_IN_PAGE %>;
            for (var i = begin; i < end; i++) {
                $('#divAlbumPhoto' + i).css('display', 'none');
            }
            $('#pageIndexAlbum' + indexAlbumVisible).css('color', 'inherit');

            //Visible
            indexAlbumVisible = albumPage;
            begin = (albumPage - 1)*<%=WebHoiChoMuaBan.Controllers.Global.Config.NUM_ALBUM_SHOW_IN_PAGE %> + 1;
            end = begin + <%=WebHoiChoMuaBan.Controllers.Global.Config.NUM_ALBUM_SHOW_IN_PAGE %>;
            for (var i = begin; i < end; i++) {
                $('#divAlbumPhoto' + i).css('display', 'inline');
            }

            $('#pageIndexAlbum' + albumPage).css('color', 'red');
        }

        ////////////Photo of album///////////////
        function PreviewPhotoOfAlbum() {
            if ($('#aNextPhotoOfAlbum').css('visibility') == "hidden")
                $('#aNextPhotoOfAlbum').css('visibility', 'visible');
            for (var i = maxCurrentPage - 3; i <= maxCurrentPage; i++) {
                $('#aPhotoOfAlbum' + i).css('display', 'none');
            }
            maxCurrentPage = maxCurrentPage - 4;
            if (maxCurrentPage < pageNumVisible){
                maxCurrentPage = pageNumVisible;
                $('#aPreviewPhotoOfAlbum').css('visibility', 'hidden');
            }
            for (var i = maxCurrentPage; i >= maxCurrentPage - 3; i--) {
                $('#aPhotoOfAlbum' + i).css('display', 'inline');
            }
        }

        function NextPhotoOfAlbum() {
            if ($('#aPreviewPhotoOfAlbum').css('visibility') == "hidden")
                $('#aPreviewPhotoOfAlbum').css('visibility', 'visible');
            for (var i = maxCurrentPage - 3; i <= maxCurrentPage; i++) {
                $('#aPhotoOfAlbum' + i).css('display', 'none');
            }
            maxCurrentPage = maxCurrentPage + 4;
            if (maxCurrentPage > totalPage){
                maxCurrentPage = totalPage;
                $('#aNextPhotoOfAlbum').css('visibility', 'hidden');
            }
            for (var i = maxCurrentPage; i >= maxCurrentPage - 3; i--) {
                $('#aPhotoOfAlbum' + i).css('display', 'inline');
            }
        }

        function ToIndexPhotoOfAlbum(page){
            //Hidden
            $('#pageAvailable' + indexPhotoAlbum).css('display', 'none');
            $('#aPhotoOfAlbum' + indexPhotoAlbum).css('color', 'inherit');

            //Visible
            indexPhotoAlbum = page;
            $('#pageAvailable' + page).css('display', 'inline');
            $('#aPhotoOfAlbum' + page).css('color', 'red');
        }
    </script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentHolder" runat="server">
    <div class="private_share_post_top">
        <div class="private_sharepost_menu">
            <ul>
                <li><a href="#" class="menu_select">Photo</a></li>
            </ul>
        </div>
        <div class="private_write_right private_margin_topright">
            <div class="private_button_upload">
                <a href="<%=Url.Action("Upload", "Photo")%>">
                    <img src="/../Content/Images/icon_plus_up.gif" />
                    Đăng tải photo</a>
            </div>
        </div>
    </div>
    <div class="private_content_onecol">
        <div class="private_maxim_title">
            <div class="private_bt_member_left private_font_bold">
                Album mới</div>
            <div class="private_post_product">
                <a id="aPreview" href="javascript:void(0)" onclick="Preview()" style="visibility:hidden; text-decoration:none;"><< </a>
                <%
                    int nTotalPage = (int)Math.Ceiling(double.Parse(ViewData["NumAlbums"].ToString()) / WebHoiChoMuaBan.Controllers.Global.Config.PAGE_NUMBER_VISIABLE);
                    for (int i = 1; i <= nTotalPage; i++)
			        {
                        if (i <= WebHoiChoMuaBan.Controllers.Global.Config.PAGE_NUMBER_VISIABLE)
                        {
		        %>
                        <a id="pageIndexAlbum<%=i %>" href="javascript:void(0)" onclick="ToIndexAlbum(<%=i %>)" style="text-decoration:none; display:inline;"> <%=i %> </a>|
                <%
                        }else{
                %>
                        <a id="pageIndexAlbum<%=i %>" href="javascript:void(0)" onclick="ToIndexAlbum(<%=i %>)" style="text-decoration:none; display:none;"> <%=i %> </a>|
                <%
                        }
			        }
                    if (nTotalPage > WebHoiChoMuaBan.Controllers.Global.Config.PAGE_NUMBER_VISIABLE)
                    {
                %>
                <a id="aNext" href="javascript:void(0)" onclick="Next();" style="text-decoration:none;"> >></a>
                <%} %>
            </div>
        </div>
        <!-- Photo new -->
        <div class="private_photo">
            <%--<!-- Photo new thumb-->
            <div class="private_photo_thum">
                <a href="photo_detail_private.html">
                    <img src="/../Content/Images/photo.gif" class="private_img_photo" /></a>
                <div class="private_bt_delete">
                    <a href="#">
                        <img src="/../Content/Images/delete_bt.gif" alt=""></a></div>
            </div>--%>
            <!-- End Photo new thumb-->
            <%
                if (ViewData["ListAlbums"] != null)
                {
                    List<WebHoiChoMuaBan.Models.PhotoAlbum> albums = (List<WebHoiChoMuaBan.Models.PhotoAlbum>)ViewData["ListAlbums"];
                    int i = 0;
                    foreach (var album in albums)
                    {
                        i++;
            %>
                <div id="divAlbumPhoto<%=i %>" class='private_photo_thum'
                <%
                    if (i > WebHoiChoMuaBan.Controllers.Global.Config.NUM_ALBUM_SHOW_IN_PAGE)
                    {
                %>
                    style="display:none;">
                    <%}
                    else
                    {%> 
                    style="display:inline;">
                    <%} %>
                    <a href='<%=Url.Action("List", "Photo", new { uid = ViewData["MemId"], albumId = album.AlbumId }) %>'>
                        <img src='/../Content/Images/Upload/Thumbnail/<%=album.AlbumThumb %>' class='private_img_photo' />
                    </a>
                    <div class='private_bt_delete'>
                        <%--<a href="/Photo/DeleteAlbum?uid=<%=album.MemId %>&albumId=<%=album.AlbumId %>">--%>
                        <a href="<%= Url.Action("DeleteAlbum","Photo", new {albumId = album.AlbumId}) %>">
                            <img src='/../Content/Images/delete_bt.gif' alt='' />
                        </a>
                    </div>
                </div>
            <%
                    }
                }
                else
                {
                    Response.Write("Chưa có album !."); 
                }
            %>
        </div>
        <!-- End Photo new -->
        <div class="private_maxim_title">
            <div class="private_bt_member_left private_font_bold">
                Danh sách hình mới</div>
            <div class="private_post_product">
                <a id="aPreviewPhotoOfAlbum" href="javascript:void(0)" onclick="PreviewPhotoOfAlbum()" style="visibility:hidden; text-decoration:none;"><< </a>
                <%
                    int nNumPhoto = int.Parse(ViewData["NumPhoto"].ToString());
                    int nPhotoAvailable = WebHoiChoMuaBan.Controllers.Global.Config.ROWS_PHOTO_LIST * WebHoiChoMuaBan.Controllers.Global.Config.COLS_PHOTO_LIST;
                    int nNumPage = (int)Math.Ceiling((double)nNumPhoto / nPhotoAvailable);
                    for (int j = 1; j <= nNumPage; j++)
                    {
                        if (j <= WebHoiChoMuaBan.Controllers.Global.Config.PAGE_NUMBER_VISIABLE)
                        {
		        %>
                        <a id="aPhotoOfAlbum<%=j%>" href="javascript:void(0)" onclick="ToIndexPhotoOfAlbum(<%=j %>)" style="text-decoration:none; display:inline;"> <%=j %> </a>|
                <%
                        }else{
                %>
                        <a id="aPhotoOfAlbum<%=j%>" href="javascript:void(0)" onclick="ToIndexPhotoOfAlbum(<%=j %>)" style="text-decoration:none; display:none;"> <%=j %> </a>|
                <%
                        }
                    }
                    if (nNumPage > WebHoiChoMuaBan.Controllers.Global.Config.PAGE_NUMBER_VISIABLE)
                    {
                %>
                    <a id="aNextPhotoOfAlbum" href="javascript:void(0)" onclick="NextPhotoOfAlbum()" style="text-decoration:none;"> >></a>
                <%} %>
            </div>
        </div>
        <!-- Photo new -->
        <div class="private_photo">
            <!-- Photo new thumb-->
            <%
                List<WebHoiChoMuaBan.Models.Photo> listPhotos = ViewData["ListPhotoOfAlbum"] as List<WebHoiChoMuaBan.Models.Photo>;
                int indexPageAvailable = 1;
                int albumID = (int)ViewData["albumID"];
                for (int nPhoto = 0; nPhoto < nNumPhoto && listPhotos != null; nPhoto++)
                {
                    if (nPhoto % nPhotoAvailable == 0)
                    {
            %>
                        <div id="pageAvailable<%=indexPageAvailable %>" style="display: none;">
                    <%} %>
                            <div class="private_photo_thum">
                                <a href='<%=Url.Action("Detail", "Photo", new { uid = ViewData["MemId"], albumID, photoId = listPhotos[nPhoto].PhotoId}) %>'>
                                    <img src="/../Content/Images/Upload/Thumbnail/thumbnail_<%=listPhotos[nPhoto].PhotoFileName %>" class="private_img_photo" /></a>
                                <div class="private_bt_delete">
                                    <a href="<%= Url.Action("DeletePhoto","Photo", new {photoId = listPhotos[nPhoto].PhotoId}) %>">
                                        <img src="/../Content/Images/delete_bt.gif" alt="" /></a></div>
                            </div>
            <%
                    if (nPhoto % nPhotoAvailable == nPhotoAvailable - 1)
                    {
                        indexPageAvailable++;
            %>
                        </div>
            <%
                    }
                } 
            %>
            <!-- End Photo new thumb-->
        </div>
        <!-- End Photo new -->
    </div>
</asp:Content>
